function bciGridPlot(prm,X,Y,dat,Lbl)

if ~isfield(prm,'electrodes'),
    prm.electrodes = 'on';
end

channelPosition = [X,Y];
% We use a Delaunay trangulation to construct the surface
tri = delaunay(channelPosition(:,1),channelPosition(:,2));
%and plot it
colorVals=zeros(size(channelPosition,1),1);
if isfield(prm,'maplimits'),
    clFixed=1;
    cl=colorLim;
else
    clFixed=0;
end

set(gcf,'color','w')
if ~clFixed
    cl=max(abs(dat));
    cl=[-cl cl];
end
pH=trisurf(tri,channelPosition(:,1),channelPosition(:,2),zeros(size(dat)),dat);
set(gca,'clim',cl,'zlim',cl,'box','off','gridlinestyle','none','color','none','linewidth',1,'fontweight','bold');

alphamap('vdown')
set(pH,'FaceAlpha','interp','AlphaDataMapping','scaled','FaceVertexAlphaData',colorVals);

set(gca,'dataaspectratio',[1 1 1])

shading interp
if strcmpi(prm.electrodes,'on'),
    hold on;
    plot(X,Y,'k.');
    hold off;
elseif strcmpi(prm.electrodes,'labels'),
    if ~exist('Lbl'),
        Lbl={int2str([1:length(X)]')};        
    end
	hold on;
    %text(x(i), y(i), chanLabels{i}, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'FontSize', 8);
    text(X,Y,Lbl);
    hold off;
end

axis off
view([0 90])
xlim([min(X),max(X)]);
ylim([min(Y),max(Y)]);
